          SUBROUTINE (UMTBL,UMQTY,LARGEST.UM,IQ,Q1,U1,Q2,U2,ALPHA,FORCE.LG)
** Version# 12.0002[12] - 05/04/2017 - 03:46pm - TSMITH - eclipse
*** V12.0002 Change - Custom Coding . - 05/04/2017 - TSMITH - eclipse
** Copied from BP IQ.TO.ALPHA Version# 12 - 03/08/2007 - 12:09pm - ANNEM - r8.0base

*** Subroutine : IQ.TO.ALPHA
*-------------------------------------------------------------------------*
*** This subroutine coverts the internal quantity (IQ) to an alphanumeric
*** quantity (23bx 5ea, for example)
***
*** NOTE: This is used in places other than Order Entry (so don't assume
***       that led will be valid).
*-------------------------------------------------------------------------*
*** UMTBL       - Unit of Measure Table                            (IN/OUT)
*** UMQTY       - Unit of Measure Quanity (often PRD(7))           [IN]
*** LARGEST.UM  - Largest unit of measure to use during conversion (IN)
*** IQ          - Internal Quantity                                [IN]
*** Q1          - Quantity 1                                       (OUT)
*** U1          - Unit of measure 1                                (OUT)
*** Q2          - Quantity 2                                       (OUT)
*** U2          - Unit of measure 2                                (OUT)
*** ALPHA       - Alpha numeric unit and unit of measure           (OUT)
*** FORCE.LG    - Boolean.  If this is true, then the LARGEST.UM   (IN)
***             - will always be displayed.
*-------------------------------------------------------------------------*
*** Common Variables Used: PRD
*-------------------------------------------------------------------------*
          *** If these variables are not initialised, a calling
          *** program will get error messages when IQ = 0
          BEGIN CASE
          CASE IQ < 0
          IQ = 0
          CASE OCONV(UMTBL,'MCU') = 'FT'
          IQ = 0
          CASE OCONV(UMTBL,'MCU') = 'CS' OR OCONV(UMTBL,'MCU') = 'PK'
          IQ = 1
          END CASE


          Q1  = 0
          QIQ = IQ
          U1  = 0
          Q2  = 0
          U2  = ''

          IF IQ+0 = 0 THEN
             ALPHA = ''
             RETURN
          END
          IF PRD(15) # '' AND UMTBL # '' THEN UMTBL = PRD(15)
          IF UMTBL<1,1> # '' THEN DFLT.UM = UMTBL<1,1> ELSE DFLT.UM = "ea"

          *** Find what to use as the largest unit of measure to output
          LOCATE LARGEST.UM IN UMTBL<1> SETTING ULM ELSE ULM = 5
          LPOS = ULM

          *** Run through backwards from the largest unit of measure
          *** down to get the first (highest) unit of measure and quantity
          FOR UL = ULM TO 1 STEP -1 WHILE Q1 = 0

             UMQ = TRIM(UMQTY<1,UL>)+0
             UMA = TRIM(UMTBL<1,UL>)
             IF UMA # '' AND UMQ THEN
                Q   = INT(IQ/UMQ)
                Q1  = Q
                QIQ = IQ - Q * UMQ
                U1  = UMA
                ULM = UL - 1
             END

             IF FORCE.LG THEN EXIT
          NEXT UL

          *** Run through backwards from the largest unit of measure
          *** down to get the second (highest) unit of measure and
          *** quantity making sure there is no remainder.
          BEGIN CASE
          CASE FORCE.LG AND Q1 = 0
             *** In this case, we want to make sure that the LARGEST.UM
             *** is displayed regardless of wether or no there is
             *** quantity enouph to fill it.
             Q1 = 0
             U1 = UMTBL<1,LPOS>
             Q2 = IQ
             U2 = DFLT.UM
          CASE Q1 = 0
             *** If Q1 is 0 then nothing more can be done
             Q1 = IQ
             U1 = DFLT.UM
             Q2 = ''
             U2 = ''
          CASE QIQ = 0
             U1 = UMA
             Q2 = ''
             U2 = ''
          CASE OTHERWISE
             Q2 = 0
             FOR UL=ULM TO 1 STEP -1 WHILE Q2=0
                UMQ=UMQTY<1,UL>
                UMA=UMTBL<1,UL>
                IF UMA#'' AND UMQ THEN
                   Q=INT(QIQ/UMQ)
                   IF QIQ-Q*UMQ=0 THEN Q2=Q; U2=UMA
                END
             NEXT UL
             IF Q2=0 THEN Q2=QIQ; U2=DFLT.UM
          END CASE

*** Create ALPHA by concatinating all quantities and units of measure
          BEGIN CASE
          CASE LEN(Q1) > 5 OR LEN(Q2) > 5
             *** Make sure the whole qty fields displays! Without this
             *** 123456ea ends up 23456ea. Or 1cs 1234ea ends up
             *** 1cs 234ea where there are 10000ea per cs.
             ALPHA = Q1
          CASE LEN(Q2) > 3
             Q1.FMT = 'R#':(5-(LEN(Q2)-3))
             ALPHA = Q1 Q1.FMT
          CASE OTHERWISE
             ALPHA = Q1"R#5"
          END CASE
          RETURN
!TSMITH~05/04/17~15:46
